/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package databeans;

import beans.*;
import com.sun.rowset.CachedRowSetImpl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import javax.sql.rowset.CachedRowSet;
import utils.CargarConfiguraciones;

/**
 *
 * @author Emerson
 */
public class MateriaAlumnoDataBean {
private CachedRowSet rowSet;
private CargarConfiguraciones cc;

public MateriaAlumnoDataBean() throws Exception{
        cc = new CargarConfiguraciones();
        Class.forName(cc.getValor("driver"));
        rowSet = new CachedRowSetImpl();
        rowSet.setUrl(cc.getValor("urlbase"));
        rowSet.setUsername(cc.getValor("usuario"));
        rowSet.setPassword(cc.getValor("clave"));
}

public void borrarMateriaAlumno(String carnet, String codMateria) throws SQLException{

    String sql ="delete from alumno_materia " +
            "where " +
            "carnet='"+carnet+"' " +
            "and codmateria = '"+codMateria+"'";
        rowSet.setCommand(sql);
        rowSet.execute();


}

public void setMateriasAlumno (ArrayList <AlumnoMateriaBean> materias_alumno) throws SQLException{
        
     Iterator it = materias_alumno.iterator();
     while(it.hasNext()){
     AlumnoMateriaBean aux= (AlumnoMateriaBean) it.next();
     
     String sql="INSERT INTO alumno_materia (" +
                        "carnet, " +
                        "codmateria)" +
                        
                "VALUES (" +
                        "'" + aux.getCarnet() + "'," +
                        "'" + aux.getCodmateria() + "')";
        rowSet.setCommand(sql);
        rowSet.execute();
     }
 }

}
